package bdcin.fachada;

import java.io.IOException;
import java.util.Properties;

import br.cin.ufpe.in1118.middleware.distribution.services.naming.Naming;
import br.cin.ufpe.in1118.middleware.distribution.services.naming.NamingService;
import br.cin.ufpe.in1118.middleware.exceptions.RemoteException;


public final class BDCInFactory {

	private BDCInFactory() { }
	
	private static Properties prop;
	
	static {
		try {
			prop = new Properties();
			prop.load(BDCInFactory.class.getResourceAsStream("/middleware.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static IBDCIn getFacade() {
		IBDCIn ibdcin = null;
		Naming naming = NamingService.getNamingInstance(prop.getProperty("naming.server.host"), Integer.parseInt(prop.getProperty("naming.server.port")));
		try {
			Object obj = naming.lookup(IBDCIn.SERVICE_NAME);
			if (obj instanceof IBDCIn) {
				ibdcin = (IBDCIn) obj;
			}
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return ibdcin;
	}

}
